//
//  SAWHomeworkModel.m
//  优学荟管理系统
//
//  Created by edz on 2018/1/26.
//  Copyright © 2018年 星道三好. All rights reserved.
//

#import "SAWHomeworkModel.h"

@implementation SAWHomeworkModel
- (void)setNetWork:(void(^)(NSDictionary *dic))succedDic
{
  
    
    NSString *url= @"consolidate.do?action=getSelectableInfo";
    
    NSLog(@"%@ %@",LLBaseURLTeacher(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    [NetManager Get:LLBaseURLTeacher(url) Auth:YES Params:nil Success:^(id Obj) {
        
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            [SVProgressHUD dismiss];
       
            if (succedDic) {
                succedDic(Obj[@"t"]);
            }
           
            
        }
        
        else {
            [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
           
        }
        
      
        
        
    } Fail:^(NSError *Error) {
        [SVProgressHUD showErrorWithStatus:NetErr];
        
    }];
    
    
    
    
}
//获取单元
-(void)getUserXQ:(NSArray *)arr withData:(void(^)(NSArray *array))succedDic
{
    
    
    NSString *url= [NSString stringWithFormat:@"yxhUser.do?action=getunitbyquery&termType=%@&gradeid=%@&subjectid=%@&tid=%@",arr[3],arr[2],arr[0],arr[1]];
    
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    
    [NetManager Post:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            [SVProgressHUD dismiss];
            
           
            if (succedDic) {
                succedDic(Obj[@"t"]);
            }
            
            
        }
        
        else {
            [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
            
        }
        
        
        
        
    } Fail:^(NSError *Error) {
        [SVProgressHUD showErrorWithStatus:NetErr];
        
    }];
    
    
    
    
}
//保存接口
-(void)savaData:(NSArray *)arr withData:(void(^)(NSString *homeworkID))succed
{
    
    
    NSString *str= [NSString stringWithFormat:@"assignHomework.do?action=saveKnowpointHomeWork&lessonId=%@&title=%@&uids=%@",arr[0],arr[1],arr[2]];
    NSString *url = [str  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    
    [NetManager Post:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            [SVProgressHUD dismiss];
            
            
            if (succed) {
                succed(Obj[@"t"]);
            }
            
            
        }
        
        else {
            [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
            
        }
        
        
        
        
    } Fail:^(NSError *Error) {
        [SVProgressHUD showErrorWithStatus:NetErr];
        
    }];
    
    
    
    
}
//获取知识点
- (void)getKnowLage:(NSString *)lessID succed:(void(^)(NSArray *dataArr))dataArr
{
    
    
    NSString *url= [NSString stringWithFormat:@"assignHomework.do?action=getKnowpointlist2&lessonId=%@",lessID];
    
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    [NetManager Get:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            [SVProgressHUD dismiss];
            
            if (dataArr) {
                dataArr(Obj[@"t"]);
            }
            
            
        }
        
        else {
            [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
            
        }
        
        
        
        
    } Fail:^(NSError *Error) {
        [SVProgressHUD showErrorWithStatus:NetErr];
        
    }];
    
    
    
    
}
@end
